package asteroids.model.programs.statements;

import exception.StopActionClassException;
import asteroids.model.programs.Expression;
import asteroids.model.programs.Program;

public class If extends Statement {
	
	public If(Expression<?> condition, Statement than, Statement otherwise){
		this.condition=condition;
		this.than=than;
		this.otherwise=otherwise;
	}

	private Expression<?> condition;
	private Statement than;
	private Statement otherwise;
	
	@Override
	public void execute(Program program) throws StopActionClassException {
		if(!isExecuted()){
		if((Boolean)condition.getValue(program))
			than.execute(program);
		else
			otherwise.execute(program);
		setExecuted();
		}
	}

	@Override
	public void reset() {
		setUnexecuted();
		than.reset();
		otherwise.reset();
	}

}
